package com.weakteam.orderonline.adminconsole.gwt.client.domain;

import com.google.gwt.json.client.*;

/**
 * @author Nail
 */
public class Goods {
    private Integer id;

    private Integer menuId;

    private Integer order;

    private String name;

    private String description = "";

    private Double price = 0.0;

    private String ico = "";

    private String image = "";

    private Boolean enabled = true;

    private String properties = "";

    public Goods () {}

    public Goods(JSONObject obj) {
        this.set(obj);
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getMenuId() {
        return menuId;
    }

    public void setMenuId(Integer menuId) {
        this.menuId = menuId;
    }

    public Integer getOrder() {
        return order;
    }

    public void setOrder(Integer order) {
        this.order = order;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Double getPrice() { return price; }

    public void setPrice(Double price) {
        this.price = price;
    }

    public String getIco() {
        return ico;
    }

    public void setIco(String ico) {
        this.ico = ico;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public Boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    public String getProperties() {
        return properties;
    }

    public void setProperties(String properties) {
        this.properties = properties;
    }

    public void set(JSONObject jsonObj) {
        JSONNumber jId = jsonObj.get("id").isNumber();
        if (jId != null) this.id = (int)jId.doubleValue();
        //ConsoleLog.getInstance().debug("id=" + id);

        JSONNumber jMenuId = jsonObj.get("menuId").isNumber();
        if (jMenuId != null) this.menuId = (int)jMenuId.doubleValue();
        //ConsoleLog.getInstance().debug("menuId=" + menuId);

        JSONNumber jOrder = jsonObj.get("order").isNumber();
        if (jOrder != null) this.order = (int)jOrder.doubleValue();
        //ConsoleLog.getInstance().debug("order=" + order);


        JSONString jName = jsonObj.get("name").isString();
        if (jName != null) this.name = jName.stringValue();
        //ConsoleLog.getInstance().debug("name=" + name);

        JSONString jDescription = jsonObj.get("description").isString();
        if (jDescription != null) this.description = jDescription.stringValue();
        //ConsoleLog.getInstance().debug("description=" + description);

        JSONNumber jPrice = jsonObj.get("price").isNumber();
        if (jPrice != null) this.price = jPrice.doubleValue();
        //ConsoleLog.getInstance().debug("price=" + price);


        JSONString jIco = jsonObj.get("ico").isString();
        if (jIco != null) this.ico = jIco.stringValue();
        //ConsoleLog.getInstance().debug("ico=" + ico);


        JSONString jImage = jsonObj.get("image").isString();
        if (jImage != null) this.image = jImage.stringValue();
        //ConsoleLog.getInstance().debug("image=" + image);

        JSONBoolean jEnabled = jsonObj.get("enabled").isBoolean();
        if (jEnabled != null) this.enabled = jEnabled.booleanValue();
        //ConsoleLog.getInstance().debug("enabled=" + enabled);


        JSONString jProperties = jsonObj.get("properties").isString();
        if (jProperties != null) this.properties = jProperties.stringValue();
        //ConsoleLog.getInstance().debug("properties=" + properties);
    }

    public JSONObject getJSON() {
        JSONObject jsonObject = new JSONObject();
        if (id != null) {
            jsonObject.put("id", new JSONNumber(this.id));
        } else {
            jsonObject.put("id", JSONNull.getInstance());
        }

        if (menuId != null) {
            jsonObject.put("menuId", new JSONNumber(this.menuId));
        } else {
            jsonObject.put("menuId", JSONNull.getInstance());
        }

        if (order != null) {
            jsonObject.put("order", new JSONNumber(this.order));
        } else {
            jsonObject.put("order", JSONNull.getInstance());
        }

        if (name != null) {
            jsonObject.put("name", new JSONString(this.name));
        } else {
            jsonObject.put("name", JSONNull.getInstance());
        }

        if (description != null) {
            jsonObject.put("description", new JSONString(this.description));
        } else {
            jsonObject.put("description", JSONNull.getInstance());
        }

        if (price != null) {
            jsonObject.put("price", new JSONNumber(this.price));
        } else {
            jsonObject.put("price", JSONNull.getInstance());
        }

        if (ico != null) {
            jsonObject.put("ico", new JSONString(this.ico));
        } else {
            jsonObject.put("ico", JSONNull.getInstance());
        }

        if (image != null) {
            jsonObject.put("image", new JSONString(this.image));
        } else {
            jsonObject.put("image", JSONNull.getInstance());
        }

        if (enabled != null) {
            jsonObject.put("enabled", JSONBoolean.getInstance(this.enabled));
        } else {
            jsonObject.put("enabled", JSONNull.getInstance());
        }

        if (properties != null) {
            jsonObject.put("properties", new JSONString(this.properties));
        } else {
            jsonObject.put("properties", JSONNull.getInstance());
        }

        return jsonObject;
    }
}
